import { Provide } from '@midwayjs/decorator';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { ClassifyEntity } from 'src/entity/classify/classify';
import { Repository  } from 'typeorm'

/**
 * 描述
 */
@Provide()
export class ClassifyService  {
  @InjectEntityModel(ClassifyEntity)
  ClassifyModel: Repository<ClassifyEntity>;

  /**
   * 描述
   */

  // 获取父亲id
  async getclasspid() {
       let result    = await this.ClassifyModel.createQueryBuilder('class')
          .where('class.pid is null')
          .getMany()
          return   { 
            code:20000,
            message:"成功",
            data:{result}
          }
  }
  // 获取所有class
  
  async getclass() {
       let result    = await this.ClassifyModel.createQueryBuilder('class')
          .getMany()
          return   { 
            code:20000,
            message:"成功",
            data:{result}
          }
  }

  // 添加分类
  async addclasspid(option) {
       let result    = await this.ClassifyModel.createQueryBuilder('class')
       .insert()
       .into(ClassifyEntity)
       .values( option)
       .execute();
          return   { 
            code:20000,
            message:"成功",
            data:result
          }
  }
}
